@extends('Admin.layouts.common')

@section('content')
    <div class="container myContainer">

        @if(count($errors))
            <div class="alert alert-danger">
                <ul>
                    @foreach($errors->all() as $err)
                        <li>{{ $err }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <div class="section_body">
            <div id="wrapper">
                <div id="container">
                    <!--头部，相册选择和格式选择-->
                    <div id="uploader">
                        <div class="queueList">
                            <div id="dndArea" class="placeholder">
                                <div id="filePicker"></div>
                                <p>上传一张图片</p>
                            </div>
                        </div>
                        <div class="statusBar" style="display:none;">
                            <div class="progress">
                                <span class="text">0%</span>
                                <span class="percentage"></span>
                            </div><div class="info"></div>
                            <div class="btns">
                                <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <em style="display:none" id="upload_button">上传</em>
        </div>

        <form method="post">
            {{ csrf_field() }}
            <div class="form-group">
                <label class="control-label">IMG</label>
                <?php if(!empty($data->img)):?>
                    <img src="/{{$data->img}}">
                <?php endif;?>
            </div>
            <div class="form-group required">
                <label class="control-label">标题</label>
                <select class="form-control" name="theme_id">
                    <option value="">请选择分类</option>
                    @foreach($cat as $c)
                        <option value="{{ $c->id}}" <?php if($data->theme_id==$c->id):?>selected=""<?php endif;?>>{{ $c->cat_name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="form-group required">
                <label class="control-label">标题</label>
                <input name="title" type="text" class="form-control" value="{{ old('title') ? old('title') : $data->title }}">
            </div>

            
            <div class="clearfix"></div>
            <div class="form-group required">
                <label class="control-label">内容</label>
                <div id="test-editormd">
                <textarea  style="display:none;" id="content" name="content" rows="5" class="form-control" required>{{ old('content') ? old('content') : $data->content }}</textarea></div>
                <a href="/libs/editormd/examples/index.html" target="_blank">编辑器演示</a>
            </div>
            
            
            <div class="form-group">
                <input id="goods_img" type="hidden" name="img" value="" />
                <input type="hidden" name="id" value="{{ $data->id }}">
                <button class="btn btn-primary btn-block" type="submit">编辑</button>
            </div>
        </form>
    </div>
@endsection


@section('foot')
    
    <link rel="stylesheet" href="/libs/editormd/css/editormd.css?v=<?=config('version')?>" />
    
    <script src="/libs/editormd/editormd.min.js?v=<?=config('version')?>"></script>
        <script type="text/javascript">
            var testEditor;

            $(function() {
                testEditor = editormd("test-editormd", {
                    width   : "90%",
                    height  : 640,
                    syncScrolling : "single",
                    path    : "/libs/editormd/lib/",
                    markdown : "",
                    /**上传图片相关配置如下*/
                    imageUpload : true,
                    imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                    //imageUploadURL : "{{ env('APP_URL') }}/upload/uploadmd",//注意你后端的上传图片服务地址
                    imageUploadURL : "/upload/uploadmd",
                });
                
                /*
                // or
                testEditor = editormd({
                    id      : "test-editormd",
                    width   : "90%",
                    height  : 640,
                    path    : "../lib/"
                });
                */
            });
        </script>



    <?php /*?>
    <script src="{{ asset('libs/ckeditor/ckeditor.js') }}"></script>
    <script>var editor = CKEDITOR.replace('content');</script>
    <?php */?>

    <script type="text/javascript" src="/libs/webupload/dist/webuploader.js?v=<?=config('version')?>"></script>
    <script type="text/javascript" src="/libs/webupload/uploadone.js?v=<?=config('version')?>"></script>
    <link rel="stylesheet" type="text/css" href="/libs/webupload/style.css?v=<?=config('version')?>" />
    <link rel="stylesheet" type="text/css" href="/libs/webupload/css/webuploader.css?v=<?=config('version')?>" />
@endsection
